package com.to.aboomy.bannersample.slice;

import com.to.aboomy.banner.Banner;
import com.to.aboomy.banner.Indicator;
import com.to.aboomy.banner.IndicatorView;
import com.to.aboomy.bannersample.ResourceTable;
import com.to.aboomy.bannersample.indicator.CircleIndicatorView;
import com.to.aboomy.bannersample.indicator.DashPointView;
import com.to.aboomy.bannersample.indicator.DashReverseView;
import com.to.aboomy.bannersample.indicator.FillIndicatorView;
import com.to.aboomy.bannersample.indicator.LineIndicatorView;
import com.to.aboomy.bannersample.util.ArrayStringItemSelectDialog;
import com.to.aboomy.bannersample.util.Utils;
import com.to.aboomy.bannersample.viewpager.creator.ImageRoundHolderCreator;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.utils.Color;

import java.util.Arrays;
import java.util.List;

/**
 * @since 2021-08-05
 */
public class Indicator2AbilitySclice extends AbilitySlice {
    private Banner banner;
    private int initChoose1 = 0;
    private static final String[] INDICATOR = {
            "DashPointView",
            "DashReverseView",
            "CircleIndicatorView",
            "CircleIndicatorView-FollowTouch",
            "LinePagerTitleIndicatorView",
            "LineIndicatorView",
            "PageIndicatorView-FILL",
            "PageIndicatorView-THIN_WORM",
            "PageIndicatorView-DROP",
            "PageIndicatorView-SWAP",
    };

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        getWindow().setStatusBarColor(Color.getIntColor("#FFFFFF"));
        setUIContent(ResourceTable.Layout_ability_indicator2);
        initView();

    }

    private void initView() {
        final List<Integer> data = Utils.getImage(5);
        banner = (Banner) findComponentById(ResourceTable.Id_indicator_banner);
        DashPointView dashPointView = new DashPointView(this);
        banner.setIndicator(dashPointView)
                .setHolderCreator(new ImageRoundHolderCreator())
                .setPages(data);
        /**
         * 转换指示器
         */
        Button button = (Button) findComponentById(ResourceTable.Id_select);
        button.setClickedListener(component -> {
            new ArrayStringItemSelectDialog(getAbility(), Arrays.asList(INDICATOR))
                    .setChoose(0)
                    .setOnItemClickListener((position, value) -> {
                        initChoose1 = position;
                        button.setText(value);
                        banner.setIndicator(getIndicator(position))
                                .setPages(data);
                    }).show();
        });

    }

    public Indicator getIndicator(int position) {
        switch (position) {
            case 0:
                return new DashPointView(this);
            case 1:
                return new DashReverseView(this);
            case 2: //没有过度动画
                return getCircleIndicatorView(true);
            case 3:
                return getCircleIndicatorView(false);
            case 4:
//                return new LinePagerTitleIndicatorView(this);
            case 5:
                return new LineIndicatorView(this); // 完成
            case 6:
                return getPageIndicatorView(AnimationType.FILL);
            case 7:
//                return getPageIndicatorView(AnimationType.THIN_WORM);
            case 8:
//                return getPageIndicatorView(AnimationType.DROP);
            case 9:
//                return getPageIndicatorView(AnimationType.SWAP);
            default:
                return new IndicatorView(this);
        }
    }

    /**
     * 获取 IndicatorView
     *
     * @param Type 类型
     * @return Indicator
     */
    private Indicator getPageIndicatorView(AnimationType Type) {
        Indicator indicator = null;
        if (Type.equals(AnimationType.FILL)) {
            indicator = new FillIndicatorView(this);
        } else if (Type.equals(AnimationType.THIN_WORM)) {

        } else if (Type.equals(AnimationType.DROP)) {

        } else if (Type.equals(AnimationType.SWAP)) {

        }
        return indicator;
    }

    private CircleIndicatorView getCircleIndicatorView(boolean isAnimation) {
        return new CircleIndicatorView(this, isAnimation);
    }

    public enum AnimationType {
        FILL,
        THIN_WORM,
        DROP,
        SWAP
    }
}
